<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp" %>
<div class="content-wrap">
    <div class="wrapper" style="bottom: 50px;">
        <ul class="nav nav-tabs">
            <li>
                <a href="#">库存列表</a>
            </li>
        </ul>
        <section class="panel panel-default">
            <div class="panel-body">
                <div class="col-lg-12">
                    <table id="stockTable" class="table table-bordered mg-t datatable">
                        <thead>
                        <tr>
                            <th hidden>id</th>
                            <th hidden>storageId</th>
                            <th>批次</th>
                            <th>有效期</th>
                            <th>大包装账面数</th>
                            <th>小包装库存量</th>
                            <th>盘点小包装</th>

                        </tr>
                        </thead>
                        <tbody>
                        <c:forEach items="${drugStockList}" var="drugStock">
                        <tr>
                            <td hidden>${drugStock.id}</td>
                            <td hidden>${drugStock.storageId}</td>
                            <td>${drugStock.batchNo}</td>
                            <td><fmt:formatDate value="${drugStock.expireDate}"
                                                pattern="yyyy-MM-dd"></fmt:formatDate></td>
                            <td>${drugStock.quantity/drugStock.packageNum}</td>
                            <td>${drugStock.quantity}</td>
                            <td><input name="quantity" htmlEscape="false" maxlength="50" class="form-control"
                                       data-parsley-required="true" data-parsley-type="number"
                                       value="${drugStock.quantity}"></td>

                        </tr>
                        </c:forEach>
                    </table>
                    &nbsp; <input class="btn btn-primary" value="保存" onclick="saveRows()">&nbsp;
                </div>
            </div>
        </section>
    </div>
</div>
<script>
    function saveRows() {
        /*从本届面获取createDateflag判断是否为空*/
       /* if(createDateflag != null && createDateflag.trim() != ""){
            toastr.error('改药品已经盘查过啦');
            return;
        }*/
        var tables = document.getElementById("stockTable");
        var tables = document.getElementById("stockTable");
        //组装传回的list
        var drugInventoryCheckList = [];
        for (var i = 1; i < tables.rows.length; i++) {
            var drugInventoryCheck = {};
            drugInventoryCheck.stockId = tables.rows[i].cells[0].innerHTML;
            drugInventoryCheck.storageId = tables.rows[i].cells[1].innerHTML;
            drugInventoryCheck.maxQuantity = tables.rows[i].cells[4].innerHTML;
            drugInventoryCheck.minQuantity = tables.rows[i].cells[5].innerHTML;
            drugInventoryCheck.actualQuantity = tables.rows[i].cells[6].childNodes[0].value;

            drugInventoryCheckList.push(drugInventoryCheck);
        }

        var drugInventoryCheckListJson = JSON.stringify(drugInventoryCheckList);
        $.ajax({
            type: "POST",
            url: '${ctx}/drug/drugInventoryCheck/saveList',
            data: drugInventoryCheckListJson,
            'contentType': 'application/json',
            dataType: "json",
            success: function (data) {
                if (data.code == "success") {
                    toastr.success('药品盘点成功');
                    $('#btnSubmit').trigger("click");
                } else {
                    toastr.error('药品盘点失败');
                }
            },
            error: function (data) {
                toastr.error('网络连接错误,请检查网络');
            }
        });
    }

</script>